home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Scheduling / Cassandra / Source / Notepad.m < prev    next >
Encoding:
Text File  |  1990-10-27  |  2.6 KB  |  134 lines

  1. //
  2. // Notepad.m
  3. // Copyright (c) 1990 by Jiro Nakamura 
  4. // All rights reserved
  5. //
  6. // Handles a notepad, opens it, lets the user modify it,
  7. //  and if anything changes, lets her or him save it before
  8. // closing it.
  9. //
  10. //    by Jiro Nakamura (ac6y@vax5.cit.cornell.edu)
  11. //
  12. // RCS Information
  13. // Revision Number->    $Revision: 2.6 $
  14. // Last Revised->        $Date: 90/10/27 17:53:35 $
  15. //
  16. static char rcsid[] = "$Id: Notepad.m,v 2.6 90/10/27 17:53:35 jiro Exp Locker: jiro $";
  17.  
  18.  
  19. #import "Notepad.h"
  20. #import "Global.h"
  21. #import "cass.h"        // for NOTEPADICON
  22. #import <appkit/Form.h>        // for Forms
  23. #import <appkit/TextField.h>
  24. #import <strings.h>        // for strcpy
  25.  
  26. // The minimum dimensions of the notepad window
  27. #define MIN_WIDTH            125.0
  28. #define MIN_HEIGHT            100.0
  29.  
  30.  
  31. @implementation Notepad
  32. + new
  33. {
  34.     pageNumber = 1;
  35.     self = [super new];
  36.     [self    setDelegate:self];
  37.     return self;
  38. }
  39.  
  40. - open:sender
  41. {
  42.     static int oldPageNumber = 0;
  43.     static char notepadFile[FILENAME_BUFFER], temp[FILENAME_BUFFER];
  44.     static BOOL alreadyInited = FALSE;
  45.     
  46.     
  47.     if( !alreadyInited)
  48.         {
  49.         alreadyInited = TRUE;
  50.         [self placeWindow: [global notepadFrame]];
  51.         [self    setTitle:     "Notepad"];
  52.         [self     setWindowIcon:     NOTEPADICON];
  53.         }
  54.         
  55.     if( pageNumber < 1)
  56.         pageNumber = 1;
  57.         
  58.     strcpy( notepadFile, [global notepadFile]);
  59.  
  60.      sprintf(temp, "%s.%d", notepadFile, pageNumber);
  61.      strcpy(notepadFile, temp);
  62.  
  63.     #ifdef DEBUG
  64.         fprintf(stderr,"Opening notepad on page %d.\n"
  65.                 "File opened is <%s>\n", 
  66.                 pageNumber, notepadFile);
  67.     #endif
  68.         
  69.     [pageNumberForm        setIntValue: pageNumber at:0];
  70.     [filenameTextField    setStringValue: notepadFile];
  71.     [self openWith:     notepadFile];
  72.     
  73.     if( oldPageNumber != pageNumber)
  74.         {
  75.         [self update];
  76.         oldPageNumber = pageNumber;
  77.         }
  78.     return self;
  79. }
  80.  
  81. - close
  82. {
  83.     [global    saveThisWindowPosition:    DEFAULTNOTEPADFRAME : self];
  84.     [super close];
  85.     return self;
  86. }
  87.  
  88. - pageBackward: sender
  89. {
  90.     pageNumber --;
  91.     if(    [self    isDocEdited])
  92.         [self save];
  93.     [self open: self];
  94.     return self;
  95. }
  96.  
  97. - pageForward: sender
  98. {
  99.     pageNumber ++;
  100.     if(    [self    isDocEdited])
  101.         [self save];
  102.     [self open: self];
  103.     return self;
  104. }
  105.  
  106. - pageFormModified: sender
  107. {
  108.     pageNumber = [pageNumberForm intValueAt: 0];
  109.     if(    [self    isDocEdited])
  110.         [self save];
  111.     [self open: self];
  112.     return self;
  113. }
  114.     
  115.     
  116. - windowWillResize: (id) sender toSize: (NXSize *) size
  117. {
  118.     #ifdef DEBUG
  119.         fprintf(stderr,"Window would have resized to %f x %f.\n",
  120.                 size->width, size->height);
  121.     #endif
  122.     
  123.     if( size->width < MIN_WIDTH)
  124.         size->width = MIN_WIDTH;
  125.     if( size->height < MIN_HEIGHT)
  126.         size->height = MIN_HEIGHT;
  127.         
  128.     #ifdef DEBUG
  129.         fprintf(stderr,"Window will resize to %f x %f.\n", size->width, size->height);
  130.     #endif
  131.     return self;
  132. }
  133. @end
  134.